package com.qst.express;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.ReadListener;
import com.qst.express.utils.DataDemo;
import com.qst.express.utils.DataListener;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author:CoolTiger
 * @title: test
 * @projectName springboot-e
 * @description: TODO
 * @date:2022/09/25/14:26:07
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class test {

    @Test
    public void easyExcelRead(){
        try {
            // 1. 上传的Excel文件路径
            String filePath = "G:\\Desktop\\测试.xls";

            // 2. 创建监听器，处理读取的数据
            ReadListener<DataDemo> listener = new DataListener();

            // 3. 读取Excel文件
            EasyExcel.read(filePath, DataDemo.class, listener).sheet().doRead();

            FileInputStream fis = new FileInputStream(filePath);
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
